/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package database;

import java.sql.*;
import java.sql.DriverManager;

/**
 *
 * @author cloud
 */
public class DBmgr {
    public static String getData(String prodotto) {
        String result = "";
        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "");
        stmt = con.createStatement();
        rs = stmt.executeQuery("REPLACE  INTO carrello (id_prodotto) VALUES ("+prodotto+")");
        rs = stmt.executeQuery("SELECT * FROM catalogo WHERE id_prod=" + prodotto);
        while (rs.next()) {
        result = rs.getString("id_prod") + rs.getString("nome") + rs.getString("prezzo"); }
        rs.close();
        stmt.close();
        con.close();
        } catch (Exception e) { e.printStackTrace(); }
        return result;
        }
}
